package com.mashibing.disruptor.v1;

import com.lmax.disruptor.EventTranslatorOneArg;
import com.lmax.disruptor.EventTranslatorTwoArg;
import com.lmax.disruptor.RingBuffer;
import java.nio.ByteBuffer;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class LongEventProducer2 {

    private final RingBuffer<LongEvent> ringBuffer;

    private static final EventTranslatorOneArg<LongEvent, ByteBuffer> TRANSLATOR1 =
            (event, sequence, bb) -> event.setValue(bb.getLong(0)+100);

    private static final EventTranslatorTwoArg<LongEvent, ByteBuffer, Long> TRANSLATOR2 =
            (event, sequence, bb, l) -> event.setValue(bb.getLong(0) * l);

    public LongEventProducer2(RingBuffer<LongEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void onData(ByteBuffer buffer, Long l) {
//        ringBuffer.publishEvent(TRANSLATOR1, buffer);
        ringBuffer.publishEvent(TRANSLATOR2, buffer, l);
        System.out.printf("\033[33m %s ===>> %s ===>> LongEventProducer2 ===>> %s \033[0m\n",
                Thread.currentThread().getName(), LocalTime.now(), buffer.getLong(0));
    }

}
